/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.service.currency;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.currency.HkUserFeedback;
import com.thinkgem.jeesite.modules.hk.sys.dao.currency.HkUserFeedbackDao;
import com.thinkgem.jeesite.modules.hk.sys.entity.currency.HkUserFeedbackImg;
import com.thinkgem.jeesite.modules.hk.sys.dao.currency.HkUserFeedbackImgDao;

/**
 * 系统反馈Service
 * @author 李欣荣
 * @version 2018-09-30
 */
@Service
@Transactional(readOnly = true)
public class HkUserFeedbackService extends CrudService<HkUserFeedbackDao, HkUserFeedback> {

	@Autowired
	private HkUserFeedbackImgDao hkUserFeedbackImgDao;
	
	public HkUserFeedback get(String id) {
		HkUserFeedback hkUserFeedback = super.get(id);
		hkUserFeedback.setHkUserFeedbackImgList(hkUserFeedbackImgDao.findList(new HkUserFeedbackImg(hkUserFeedback)));
		return hkUserFeedback;
	}
	
	public List<HkUserFeedback> findList(HkUserFeedback hkUserFeedback) {
		return super.findList(hkUserFeedback);
	}
	
	public Page<HkUserFeedback> findPage(Page<HkUserFeedback> page, HkUserFeedback hkUserFeedback) {
		return super.findPage(page, hkUserFeedback);
	}
	
	@Transactional(readOnly = false)
	public void save(HkUserFeedback hkUserFeedback) {
		super.save(hkUserFeedback);
		for (HkUserFeedbackImg hkUserFeedbackImg : hkUserFeedback.getHkUserFeedbackImgList()){
			if (hkUserFeedbackImg.getId() == null){
				continue;
			}
			if (HkUserFeedbackImg.DEL_FLAG_NORMAL.equals(hkUserFeedbackImg.getDelFlag())){
				if (StringUtils.isBlank(hkUserFeedbackImg.getId())){
					hkUserFeedbackImg.setFeedback(hkUserFeedback);
					hkUserFeedbackImg.preInsert();
					hkUserFeedbackImgDao.insert(hkUserFeedbackImg);
				}else{
					hkUserFeedbackImg.preUpdate();
					hkUserFeedbackImgDao.update(hkUserFeedbackImg);
				}
			}else{
				hkUserFeedbackImgDao.delete(hkUserFeedbackImg);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(HkUserFeedback hkUserFeedback) {
		super.delete(hkUserFeedback);
		hkUserFeedbackImgDao.delete(new HkUserFeedbackImg(hkUserFeedback));
	}
	
}